import pandas as pd
import numpy as np
import datetime

#先读取ETF的十个股票数据
#复制excel文件地址代替绿色那一块，然后在双引号前加r
df1 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\1.xls",skipfooter=6)
df2 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\2.xls",skipfooter=6,)
df3 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\3.xls",skipfooter=6,)
df4 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\4.xls",skipfooter=6,)
df5 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\5.xls",skipfooter=6,)
df6 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\6.xls",skipfooter=6,)
df7 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\7.xls",skipfooter=6,)
df8 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\8.xls",skipfooter=6,)
df9 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\9.xls",skipfooter=6,)
df10 = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\10.xls",skipfooter=6,)

dfs = [df1, df2, df3, df4, df5, df6,df7, df8, df9,df10]

arrays = []
arrays1 = []
for df in dfs:
    df = df.iloc[1:].reset_index(drop=True)
    df['涨跌幅%']= df['涨跌幅%'].astype(float)
    df['收盘价'] = df['收盘价'].astype(float)
    arrays.append(df['涨跌幅%'].values)
    arrays1.append(df['收盘价'].values)



#输入对应股票的占比，一定要一一对应，必须得是小数
ratios = [0.1325,0.0982,0.0569,0.0448,0.0368,0.0362,0.0353,0.0352,0.0345,0.0335]

result = np.zeros_like(arrays[0])#股票涨跌幅的加权相加
for array,ratio in zip(arrays,ratios):
    result += array * ratio

stockprice = np.zeros_like(arrays1[0])
for array,ratio in zip(arrays1,ratios):
    stockprice += array * ratio


ETF = pd.read_excel(r"C:\Users\86137\Desktop\新建文件夹\ETF.xls",skipfooter=6)#这里要填ETF文件名称！！！！！格式是：('XXXXXX.XX.xlsx') python的所有符号都是英文的
ETF = ETF.iloc[1:].reset_index(drop=True)
ETFprice = ETF['收盘价']

ETFarray = ETF['涨跌幅%'].values

def getrate(stockdata,EtfData):
    retMaxVal = np.max(stockdata)
    EtfMaxVal = np.max(EtfData[1:])
    rate = retMaxVal/EtfMaxVal
    return rate
rateval = getrate(result,ETFarray)



dates = df1['交易时间'].iloc[1:]


#timestamp = []
#for i in dates:
    #timestamp.append(i.timestamp())


if __name__ == "__main__":
    import matplotlib.pyplot as plt
    fig = plt.figure()
    plt.plot(dates,result,label = '股票加权涨跌幅')
    plt.plot(dates,ETFarray,label = 'ETF涨跌幅')
    plt.title('159992.SZ-stock')#名称需要改！！！！ETF基金名字
    plt.show()